const Service = require('egg').Service;

class DeptService extends Service {
    /**
     * @param {提交的数据} data 
     * @return 1，0
     */
    async add(data) {

        return 1;
    }

    /**
     * @param {提交的数据} quary 
     * @return 
     */
    async list(query) {
        const { ctx,app } = this;
        let { page, pageSize } = query;
        pageSize = pageSize || 10;
        page = page || 1;
        //查询列表
        let users = await ctx.model.query('SELECT * FROM sys_dept d WHERE d.deleted=:deleted LIMIT :offset, :limit',
            { replacements: { deleted: '0', offset: (page - 1) * pageSize, limit: pageSize * 1 }, raw: true, type: app.Sequelize.QueryTypes.SELECT });
        //查询总数
        let count = await ctx.model.query('SELECT count(*) as total FROM sys_dept d WHERE d.deleted=:deleted',
            { replacements: { deleted: '0'}, raw: true, type: app.Sequelize.QueryTypes.SELECT });

            return {
            list: users,
            total: count[0].total
        };
    }
}

module.exports = DeptService;